using System;
using System.Collections.Generic;
using Castle.ActiveRecord;
using NHibernate.Expression;
using Saffron.Framework.Users;


namespace Saffron.Framework.Messages
{
    [ActiveRecord]
    public class Message :ActiveRecordBase
    {
        private int _id;
        private UserAccount _sentBy;
        private string _subject; 
        private string _body;
        private int _projectId;
        private DateTime _createdDate;
        [PrimaryKey]
        public int Id
        {
            get { return _id; }
            set { _id = value; }
        }

        [Property(NotNull = true)]
        public string Subject
        {
            get { return _subject; }
            set { _subject = value; }
        }

        [Property(ColumnType = "StringClob")] 
        public string Body
        {
            get { return _body; }
            set { _body = value; }
        }

        [Property(NotNull  = false)]
        public int ProjectId
        {
            get { return _projectId; }
            set { _projectId = value; }

        }

        [BelongsTo("SentBy", NotNull = true)]
        public UserAccount SentBy
        {
            get { return _sentBy;  }
            set { _sentBy = value; }
        }

        [Property(NotNull = true)]
        public DateTime CreatedDate
        {
            get { return _createdDate; }
            set { _createdDate = value; }
        }
        public static List<Message> FindAllMessagesFor( UserAccount user )
        {
            List<Message> messages = new List<Message>();
            for (int i = 0; i < 20; i++)
            {
                Message msg = new Message();
                msg._id = i;
                msg._body="Test Message"+i;
                msg._subject = string.Format("This is Subject test message {0}",i);
                msg._sentBy = user;
                msg._projectId = 1;
                messages.Add(msg);
            }
            return messages;
        }

        public static Message FindMessageById(int id)
        {
             return (Message) Message.FindByPrimaryKey(typeof(Message), id); 
        }
        
    }
}
